package com.example.wenliangjiudian.controller;

import com.example.wenliangjiudian.entity.RoomType;
import com.example.wenliangjiudian.service.RoomTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class RoomTypeController {

    @Autowired
    private RoomTypeService roomTypeService;


    @RequestMapping("roomType/info")
    public Object info(HttpServletRequest request) {
        List<RoomType> list = roomTypeService.selectAll();
        request.setAttribute("list", list);
        return "back/room_type_info";
    }

    @RequestMapping("/roomType/delete")
    public Object delete(Integer typeId,HttpServletRequest request) {

        roomTypeService.delete(typeId);

        List<RoomType> list = roomTypeService.selectAll();
        request.setAttribute("list", list);
        return "back/room_type_info";
    }


    @RequestMapping("/roomType/addBtn")
    public Object addBtn(HttpServletRequest request) {


        return "back/add_room_type";
    }
    @RequestMapping("/roomType/add")
    public Object add(String typeName, HttpServletRequest request) {
        roomTypeService.add(typeName);

        List<RoomType> list = roomTypeService.selectAll();
        request.setAttribute("list", list);
        return "back/room_type_info";
    }

    @RequestMapping("/roomType/updateBtn")
    public Object updateBtn(Integer typeId, HttpServletRequest request) {

        RoomType roomType = roomTypeService.getByTypeId(typeId);
        request.setAttribute("roomType", roomType);
        return "back/update_room_type";
    }

    @RequestMapping("/roomType/update")
    public Object update(Integer typeId, String typeName, HttpServletRequest request) {
        roomTypeService.update(typeId, typeName);


        List<RoomType> list = roomTypeService.selectAll();
        request.setAttribute("list", list);
        return "back/room_type_info";
    }
}
